home *** CD-ROM | disk | FTP | other *** search
/ HyperLib 1997 Winter - Disc 1 / HYPERLIB-1997-Winter-CD1.ISO.7z / HYPERLIB-1997-Winter-CD1.ISO / オンラインウェア / BUS / TMCM Software and Labs.sit / Software for TMCM 7_95 / Files for Lab 10 / Spirals Subroutine < prev   
Text File  |  1994-05-18  |  2KB  |  55 lines

  1. { Defines a subroutine that draws "polygonal spirals"
  2.   consisting of a sequence of line segments that gradually
  3.   get longer and longer.  Try values of the parameter
  4.   close to 60, 72, 90, 120 and 180. 
  5. }
  6.  
  7.  
  8. { A subroutine definition begins with the word SUB and ends
  9.   with the word END SUB.  Just after the word SUB comes the
  10.   name of the subroutine and (optionally) a list of one
  11.   or more parameter names.  The subroutine name and the
  12.   parameters form the interface of the subroutine; everything
  13.   from there up until the END SUB is the implementation. 
  14. }
  15.  
  16.  
  17. SUB spiral(angle)   { begin definition of a subroutine named
  18.                       "spiral" with one parameter named "angle" }
  19.  
  20.    DECLARE length  { This is a "local variable" which is used
  21.                      inside the subroutine; it is part of the
  22.                      implementation and is invisible from
  23.                      outside the subroutine. }
  24.  
  25.    { The remainder of the subroutine consists of commands
  26.      that are executed every time the subroutine is used.
  27.      This subroutine could be used by saying "spiral(89.5)",
  28.      for example.  When that command is executed, the value 
  29.      89.5 is first assigned as the value of the parameter,
  30.      "angle"; then the following commands are executed.
  31.    }
  32.  
  33.    length := 0.1  
  34.    clear
  35.    home
  36.    face(0)
  37.    LOOP
  38.       forward(length)
  39.       EXIT IF abs(xcoord) > 9 OR abs(ycoord) > 9
  40.       length := length + 0.15
  41.       turn(angle)
  42.    END LOOP
  43.  
  44. END SUB  { marks the end of the subroutine }
  45.  
  46.  
  47. { You could add commands---or more subroutine definitions---
  48.   here.  When the program is run, the subroutine definition
  49.   given above merely tells the computer what "spiral" means.
  50.   After the definition, you can use subroutine spiral in
  51.   exactly the same way as a built-in subroutine like
  52.   turn or forward.
  53. }
  54.  
  55.